$(function(){
    //费用成本年份
    $("#fycb_nf").numberspinner({
        min: 2000,
        max: 2100,
        editable: true
    });
    //费用成本月份
    $("#fycb_yf").numberspinner({
        min: 1,
        max: 12,
        editable: true
    });

    $("#fycb_export").click(function(){
        window.open($.webPath() + "/zjgl/fycb/fycb_export");
    });

    var fycbclickRowIndex = null;
    $('#grid_fycb').datagrid({
        url:$.webPath() + "/zjgl/fycb/fycbList?",
        toolbar:"#toolbar_fycb",
        fitColumns: true,
        singleSelect: true,
        pagination: true,
        pageNumber:1,
        fit: true,
        rownumbers: true,
        columns:[[
            {field: 'gs_jc', title: '公司名称', width: 20},
            {field: 'yhs', title: '印花税', width: 20},
            {field: 'yysj', title: '营业税金', width: 10},
            {field: 'qtrf', title: '其他税费', width: 10},
            {field: 'rfxj', title: '税费小计', width: 20},
            {field: 'kkfy', title: '可控费用', width: 10},
            {field: 'gdfy', title: '固定费用', width: 10},
            {field: 'glfyxj', title: '管理费用小计', width: 10},
            {field: 'gzfj', title: '工资费用', width: 10},
            {field: 'lwpq', title: '劳务派遣', width: 10},
            {field: 'rlzyxj', title: '人力资源小计', width: 10}
        ]],
        onSelect: function (rowIndex, rowData) {
        },
        onLoadSuccess: function () {
        }
    });





    //费用汇总导入
    $("#fycb_inport").click(function(){
        var win = $.window({
            title:"费用成本导入",
            width:450,
            height:240,
            cache:false,
            url:$.webPath() + "/zjgl/fycb/fycb_upload",
            modal:true ,
            buttons:[
                {
                    text:'确认',
                    handler:function () {
                        $('#uploadfycb').form('submit', {
                            onSubmit:function(){
                                var upload = $("#upload").val();
                                var upload = upload.substring(upload.length-4,upload.length);
                                if(upload != ".xls"){
                                    $.messager.alert('提示', '请选择Excel文件导入', 'error');
                                    return false;
                                }
                                $(win).mask();
                            } ,
                            success:function (data) {
                                $(win).mask('hide');
                                if (data == '费用成本导入成功') {
                                    $(win).window('close');
                                    $('#grid_fycb').datagrid('reload');
                                    $.messager.show({
                                        title:'提示',
                                        msg:data,
                                        timeout:3000,
                                        showType:'slide'
                                    });
                                } else{
                                    $(win).window('close');
                                    $.messager.alert('提示', data, 'error');
                                }

                            }
                        });
                    }
                }
            ]
        });
    });

    //查询按钮
    $("#btn_fycb_search").click(function () {
        fycb_search();
    });
});

//查询科目代码
function fycb_search() {
    var fycbyf = $("#fycb_nf").val();
    var fycbnf = $("#fycb_yf").val();
    var gsMc =  $("#fycbgsId").combotree('getText') == null ? null :  $("#fycbgsId").combotree('getText');
    var gsId =  $("#fycbgsId").combotree('getValue') == null ? null :  $("#fycbgsId").combotree('getValue');
    $('#grid_fycb').datagrid('load',
        {
            fycbyf: fycbyf,
            fycbnf:fycbnf,
            gsId: gsId ,
            gsMc: gsMc
        }
    );

}





